<?php

declare (strict_types=1);


namespace App\Models\GameDB\Fantasy;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Level extends Model
{
    protected $connection = 'mysql_game';
    protected $table = 'lottery_fantasy_level';
    //protected $fillable = [];
    protected $guarded = [];

    //protected $casts = ['id' => 'int', 'user_id' => 'integer', 'amount' => 'integer', 'balance' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function one(array $filters, $orderBy = '', $sort = 'asc')
    {
        $query = self::query()->where($filters);
        if (!empty($orderBy)) {
            $query->orderBy($orderBy, $sort);
        }
        return $query->first();
    }

    public function getExpLevel($exp, $orderBy = "level", $sort = "desc")
    {
        return self::query()->where('min_exp', '<=', $exp)->orderBy($orderBy, $sort)->first();
    }

    public function listAll(array $filters, $fields)
    {
        return self::query()->where($filters)->select($fields)->get();
    }

    public function listByLevels($levelIds, $fields)
    {
        return self::query()->whereIn('level', $levelIds)->select($fields)->get();
    }

}